﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Specialized;
using DevSky.WebParts.DBConnectWP;

namespace DevSky.WebParts
{
    // http://msdn.microsoft.com/de-de/library/bb386947.aspx
    // http://www.w3schools.com/sql/sql_datatypes.asp
    public class DBTypes
    {
        private static StringCollection dtText = null;
        public static bool IsText(CustomDataColumn column)
        {
            if (dtText == null)
            {
                dtText = new StringCollection();
                dtText.Add("CHAR");
                dtText.Add("NCHAR");
                dtText.Add("VARCHAR");
                dtText.Add("NVARCHAR");
                dtText.Add("TEXT");
                dtText.Add("NTEXT");
                dtText.Add("XML");
                dtText.Add("STRING"); // .NET TYPE
            }
            return dtText.Contains(column.DataType.ToUpper());
        }

        private static StringCollection dtInt = null;
        public static bool IsInteger(CustomDataColumn column)
        {
            if (dtInt == null)
            {
                dtInt = new StringCollection();
                dtInt.Add("TINYINT");
                dtInt.Add("SMALLINT");
                dtInt.Add("INT");
                dtInt.Add("BIGINT");
            }
            return dtInt.Contains(column.DataType.ToUpper());
        }

        private static StringCollection dtDecimal = null;
        public static bool IsDecimal(CustomDataColumn column)
        {
            if (dtDecimal == null)
            {
                dtDecimal = new StringCollection();
                dtInt.Add("DECIMAL");
                dtInt.Add("REAL");
                dtInt.Add("FLOAT");
            }
            return dtDecimal.Contains(column.DataType.ToUpper());
        }

        private static StringCollection dtMoney = null;
        public static bool IsMoney(CustomDataColumn column)
        {
            if (dtMoney == null)
            {
                dtMoney = new StringCollection();
                dtMoney.Add("MONEY");
                dtMoney.Add("SMALLMONEY");
            }
            return dtMoney.Contains(column.DataType.ToUpper());
        }

        private static StringCollection dtDate = null;
        public static bool IsDateTime(CustomDataColumn column)
        {
            if (dtDate == null)
            {
                dtDate = new StringCollection();
                dtDate.Add("SMALLDATETIME");
                dtDate.Add("DATETIME");
                dtDate.Add("DATETIME2");
                dtDate.Add("DATE");
                dtDate.Add("TIME");
                dtDate.Add("DATETIMEOFFSET");
            }
            return dtDate.Contains(column.DataType.ToUpper());
        }
        
        public static bool IsImage(CustomDataColumn column)
        {
            return column.DataType.ToUpper().Equals("IMAGE");
        }

        public static bool IsBoolean(CustomDataColumn column)
        {
            return column.DataType.ToUpper().Equals("BIT");
        }

        public static bool IsBinary(CustomDataColumn column)
        {
            return column.DataType.ToUpper().Equals("BINARY") ||
                   column.DataType.ToUpper().Equals("VARBINARY");
        }

        public static bool IsGUID(CustomDataColumn column)
        {
            return column.DataType.ToUpper().Equals("UNIQUEIDENTIFIER");
        }

        public static bool IsTimeStamp(CustomDataColumn column)
        {
            return column.DataType.ToUpper().Equals("TIMESTAMP");
        }

        public static bool IsFileStream(CustomDataColumn column)
        {
            return column.DataType.ToUpper().Equals("FILESTREAM");
        }

        public static bool IsObject(CustomDataColumn column)
        {
            return column.DataType.ToUpper().Equals("SQ_VARIANT");
        }
    }
}
